<?php
namespace app\index\controller;
use think\Controller;
use think\Validate;
use think\Db;
use think\Session;
class Sendsms extends Controller
{


    public function sendsms()
    {
        $str='0123456789';
        $len=strlen($str)-1;
        $randstr='';
        for($i=0;$i<4;$i++){
            $num=mt_rand(0,$len);
            $randstr .= $str[$num];
        }   $config= Db::name('config')->find();
        $this->assign("config",$config);
        $post=input("post.");
        $PHONE=$post['mobile'];
        $CONTENT=$config['dxmb'].$randstr;
        $http = 'http://api.eait.cn/Sms/SmsHttp_U.aspx';    //短信接口
        $uid = $config['dxname'];              //用户账号
        $pwd = $config['dxpwd'];              //密码
        $time = '';
        $result = sendmsm($http,$uid,$pwd,$PHONE,$CONTENT,$time);
        $arr=explode(',',$result);
        $result=$result[0];
        Session::set('yzm',$randstr);
        if($result=='1'){
            exit(json_encode(array('status'=>'success','num'=>'')));}else{
            exit(json_encode(array('status'=>'0','num'=>'发送失败')));
        }



    }
    public function sendsmsf()
    {

        $str='abcdefghijklmnopqrstuvwxyz0123456789';
        $len=strlen($str)-1;
        $randstr='';
        for($i=0;$i<4;$i++){
            $num=mt_rand(0,$len);
            $randstr .= $str[$num];
        }    $config= Db::name('config')->find();
        $this->assign("config",$config);
        $post=input("post.");
        $user=userarray();
        if($post['mobile']==''){ return 1;exit;}
        $PHONE=$user['mobile'];
        $CONTENT=$config['dxmb'].$randstr;
        $http = 'http://api.eait.cn/Sms/SmsHttp_U.aspx';    //短信接口
        $uid = $config['dxname'];              //用户账号
        $pwd = $config['dxpwd'];              //密码
        $time = '';
        $result = sendmsm($http,$uid,$pwd,$PHONE,$CONTENT,$time);
        $arr=explode(',',$result);
        $result=$result[0];
        Session::set($user['mobile'],$randstr);
        if($result=='1'){
            exit(json_encode(array('status'=>'success','num'=>'')));}else{
            exit(json_encode(array('status'=>'0','num'=>'发送失败')));
        }



    }

}
